home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / prog / dict / d_array_test.c next >
C/C++ Source or Header  |  1994-08-05  |  2KB  |  76 lines

  1. #include <LEDA/d_array.h>
  2. #include <LEDA/list.h>
  3.  
  4. #include <LEDA/impl/avl_tree.h>
  5. #include <LEDA/impl/rb_tree.h>
  6. #include <LEDA/impl/skiplist.h>
  7. #include <LEDA/impl/ch_hash.h>
  8.  
  9.  
  10. #if !defined(__TEMPLATE_ARGS_AS_BASE__)
  11. declare3(_d_array,int,int,avl_tree)
  12. declare3(_d_array,int,int,rb_tree)
  13. declare3(_d_array,int,int,skiplist)
  14. declare3(_d_array,int,int,ch_hash)
  15. #endif
  16.  
  17. void d_array_test(d_array<int,int>& count, list<int>& L, char* name)
  18.   int min;
  19.   int max;
  20.   int x;
  21.  
  22.   cout << string("%-10s",name);
  23.   cout.flush();
  24.  
  25.   float T = used_time();
  26.  
  27.  
  28.   forall(x,L) count[x]++;
  29.  
  30.   min = max = L.head();
  31.  
  32.   forall(x,L)
  33.   { if (count[x] > count[max]) max = x;
  34.     if (count[x] < count[min]) min = x;
  35.    }
  36.  
  37.   cout << "min: " << min << " appears " << count[min] << " times, ";
  38.   cout << "max: " << max << " appears " << count[max] << " times. ";
  39.   cout << string("   (%8.2f sec)",used_time(T));
  40.   newline;
  41. }
  42.  
  43.  
  44. main()
  45. {
  46.    d_array<int,int>           RS_ARRAY(0);
  47.  
  48. #if defined(__TEMPLATE_ARGS_AS_BASE__)
  49.   _d_array<int,int,avl_tree>  AVL_ARRAY(0);
  50.   _d_array<int,int,rb_tree>   RB_ARRAY(0);
  51.   _d_array<int,int,ch_hash>   CH_ARRAY(0);
  52.   _d_array<int,int,skiplist>  SK_ARRAY(0);
  53. #else
  54.   _d_array(int,int,avl_tree)  AVL_ARRAY(0);
  55.   _d_array(int,int,rb_tree)   RB_ARRAY(0);
  56.   _d_array(int,int,ch_hash)   CH_ARRAY(0);
  57.   _d_array(int,int,skiplist)  SK_ARRAY(0);
  58. #endif
  59.  
  60.   int N = read_int("# keys = ");
  61.  
  62.   list<int> L;
  63.  
  64.   while(N--) L.append(random(1,100));
  65.  
  66.   d_array_test(AVL_ARRAY,L,"avl_tree");
  67.   d_array_test(RS_ARRAY,L,"rs_tree");
  68.   d_array_test(RB_ARRAY,L,"rb_tree");
  69.   d_array_test(CH_ARRAY,L,"ch_hash");
  70.   d_array_test(SK_ARRAY,L,"skiplist");
  71.  
  72.   return 0;
  73. }
  74.  
  75.